<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/treetable/jquery.treetable.css"/>
    <link rel="stylesheet" href="/css/treetable/jquery.treetable.theme.default.css"/>
    <script src="/layui/layui.js"></script>
    <script src="/js/libs/jquery-2.1.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/bootstrap/bootstrap-select.min.js"></script>
    <script src="/js/jq.js"></script>
    <script src="/js/main.js"></script>
    <script src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/dict.js"></script>
    <script src="/js/libs/jquery.ztree.all-3.5.min.js"></script>
    <script src="/js/my/ztree-menu.js"></script>
    <script src="/js/my/permission.js"></script>
    <script src="/js/plugin/datatables/jquery.dataTables.min.js"></script>
    <script src="/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
    <script src="/js/libs/jquery.treetable.js"></script>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
            <div class="form-group">
                <label class="col-md-2 control-label">title</label>
                <div class="col-md-8">
                    <input class="form-control" placeholder="title" type="text" name="title" id="title">
                </div>
            </div>
            <div class="form-group">
                <label class='col-md-2 control-label'>接收人</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='receiverId' id='receiverId'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='接收人'
                           type='text'
                           name='receiverName' id='receiverName'
                           readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;"
                            class="layui-btn layui-btn-sm"
                            onclick="showTableAndFlushFields('user', 'user', '用户', true, true, 'receiverId:id', 'receiverName:nickname')">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">内容</label>
                <div class="col-md-8">
					<textarea class="layui-textarea" id="demo" style="display: none">  
					</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">状态</label>
                <div class="col-md-8" style="width: 100px">
                    <select class="form-control input-sm" name="status" id="status">
                    </select>
                </div>
            </div>

            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <!--<button class="btn btn-primary" onclick="location.href='noticeList.html'">返回</button>-->
                        <button class="btn btn-primary" type="submit" onclick="save(this)">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<script type="text/javascript">
    showDictSelect("status", "noticeStatus");

    var pro = window.location.protocol;
    var host = window.location.host;
    var domain = pro + "//" + host;

    var layedit, index;
    layui.use(['layedit', 'upload'], function () {
        layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: '/files/layui?domain=' + domain,
                type: 'post'
            }
        });
        index = layedit.build('demo');
    });

    function save(obj) {
        // var title = $("#title").val();
        // var status = $("#status").val();
        // if (title.trim() == "") {
        //     layer.msg("title不能为空");
        //     return;
        // }
        // if (status.trim() == "") {
        //     layer.msg("状态不能为空");
        //     return;
        // }
        // $(obj).attr("disabled", true);

        var formdata = $("#form").serializeObject();
        // formdata.title = title;
        // formdata.status = status;
        // formdata.content = layedit.getContent(index);

        $.ajax({
            type: 'post',
            url: '/notices',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {
                layer.msg("添加成功", {shift: -1, time: 1000}, function () {
                    // location.href = "noticeList.html";
                    parent.location.reload();//关闭iFrame
                });
            }
        });
    }

</script>
</body>
</html>